using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerDataModel
{
    static int userCount = 0;
    int userid;
    string username;
    string icon;
    int level;
    int passedNum;
    SettingDataModel setting;

    public void SaveData()
    {
        string json = JsonUtility.ToJson(this);
        PlayerPrefs.SetString("user" + userid, json);
        PlayerPrefs.Save();
    }
    //public void LoadData()
    //{
    //    string json = PlayerPrefs.GetString(this.username);
    //    PlayerDataModel player = JsonUtility.FromJson<PlayerDataModel>(json);
    //    this.icon = 
    //}
    public static void CreatePlayer(PlayerDataModel player)
    {
        player.userid = userCount;
        userCount++;
        player.SaveData();
    }
    public static List<PlayerDataModel> LoadAllData()
    {
        List<PlayerDataModel> data = new List<PlayerDataModel>();
        for(int i = 0; i < userCount; i++)
        {
            string json = PlayerPrefs.GetString("user" + i);
            data.Add(JsonUtility.FromJson< PlayerDataModel>(json));
        }
        return data;
    }
}
